package com.yupi.oj.model.enums;

import cn.hutool.core.util.StrUtil;

/**
 * 代码执行状态
 *
 * @author yanghaifeng
 * @date 2024/4/26 14:45
 */
public enum ExecuteStatusEnum {
    RUNNING("1", "执行中"),
    FAILED("2", "执行失败"),
    SUCCESS("3", "执行成功");

    private final String key;
    private final String value;

    ExecuteStatusEnum(String key, String value) {
        this.key = key;
        this.value = value;
    }

    public String getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }

    /**
     * 根据 key 获取对应的 value
     *
     * @param key key
     * @return value
     */
    public static String getValueByKey(String key) {
        if (StrUtil.isBlank(key)) {
            return "";
        }
        ExecuteStatusEnum[] values = values();
        for (ExecuteStatusEnum value : values) {
            if (value.getKey().equals(key)) {
                return value.getValue();
            }
        }
        return "";
    }
}
